#!/usr/bin/env python
# -*- coding:utf8 -*-

"""
@version: 
@author: lh
@license: Apache Licence 
@contact: liuhuan0672@gmail.com
@site: 
@software: PyCharm
@file: 0004.py
@time: 2016/1/20 14:13

第 0004 题：任一个英文的纯文本文件，统计其中的单词出现的个数。
"""


def word_count(file_path):
    file_obj = open(file_path, 'r')
    word_num = 0
    for line in file_obj:
        line_list = line.split()
        word_num += len(line_list)
    file_obj.close()
    return word_num


if __name__ == '__main__':
    nums = word_count('./static/0004.txt')
    print('%s has %d words!' % ('0004.txt', nums))
